﻿using System.Collections.Generic;

namespace Sidvall.Data
{
    public class DataRowCollection<TEntity> : List<TEntity>, IDataRowProvider, IDataRowProvider<TEntity>, Sidvall.Data.ITotalRowCount
        where TEntity : class
    {
        #region Business Members

        public long? TotalRowCount { get; set; }

        #region IsReadOnly

        protected bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        #endregion

        #region Interface Members

        System.Collections.IEnumerable IDataRowProvider.DataItems
        {
            get
            {
                return this;
            }
        }
        IEnumerable<TEntity> IDataRowProvider<TEntity>.DataItems
        {
            get
            {
                return this;
            }
        }
        long ITotalRowCount.TotalRowCount
        {
            get
            {
                if (this.TotalRowCount != null)
                    return this.TotalRowCount.Value;
                return this.Count;
            }
            set
            {
                this.TotalRowCount = value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public DataRowCollection()
        {
        }

        #endregion
    }
}
